package com.zygh.lz.controller.app;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.zygh.lz.entity.Xdeclare;
import com.zygh.lz.service.XdeclareService;
import com.zygh.lz.stapprove.InBean;
import com.zygh.lz.stapprove.OutBean;
import com.zygh.lz.stapprove.OutBeanUtil;
import com.zygh.lz.stapprove.ViLog;
import com.zygh.lz.vo.ResultBean;
import com.zygh.lz.vo.ResultBeans;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "APP报备模块", description = "AppXdeclareController")
@RestController
public class AppXdeclareController {
    @Autowired
    private XdeclareService xdelclareService;

    @ApiOperation("APP新增报备")
    @PostMapping("insertXdeclare")
    @ViLog(logType = "2", module = "APP新增报备")
    public OutBean insertXdeclare(Xdeclare xdeclare, @RequestBody(required = false) InBean inBean) {
        JSONObject jsonObject = inBean.convertObj(JSONObject.class);
        xdeclare.setAppear(jsonObject.getString("appear"));
        xdeclare.setAccepter(jsonObject.getString("accepter"));
        xdeclare.setStarttime(DateUtil.now());
        xdeclare.setStoptime(DateUtil.now());
        xdeclare.setState(jsonObject.getString("state"));
        xdeclare.setConmnet(jsonObject.getString("conmnet"));
        xdeclare.setDocument(jsonObject.getString("document"));
        ResultBeans resultBeans = xdelclareService.insertXdeclare(xdeclare);
        return OutBeanUtil.resSuc(resultBeans, inBean);
    }

    /**
     * 修改
     *
     * @param xdeclare
     * @return
     */
    @PostMapping("updateXdeclareByid")
    public ResultBean updateXdeclareByid(Xdeclare xdeclare) {
        return xdelclareService.updateXdeclareByid(xdeclare);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @GetMapping("deletedeclareByid")
    public ResultBean deletedeclareByid(Integer id) {
        return xdelclareService.deletedeclareByid(id);
    }

    @GetMapping("findXdeclareByid")
    public ResultBean findXdeclareByid(Integer appear, Integer accepter, String state) {
        return xdelclareService.findXdeclareByid(appear, accepter, state);
    }
}
